package com.feicheng.house.service.impl;

import com.feicheng.house.entity.BuyOrder;
import com.feicheng.house.entity.BuyOrderClientShopVo;
import com.feicheng.house.exception.SystemException;
import com.feicheng.house.mapper.BuyOrderClientShopVoMapper;
import com.feicheng.house.mapper.BuyOrderMapper;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.IBuyOrderClientShopVoService;
import com.feicheng.house.service.IBuyOrderService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-09
 */
@Service
public class BuyOrderClientShopVoServiceImpl extends ServiceImpl<BuyOrderClientShopVoMapper, BuyOrderClientShopVo> implements IBuyOrderClientShopVoService {
	/** 订单类别头 */
    private static final String ORDER_CODE = "BR";
    
	@Autowired
	IBuyOrderService iBuyOrderService;
	/**
	 * 根据id查订单详情
	 */
	@Override
	public ResultInfo seleOne(Integer buyOrderId) {
		// TODO Auto-generated method stub
		QueryWrapper<BuyOrderClientShopVo> queryWrapper = new QueryWrapper<BuyOrderClientShopVo>();
		queryWrapper.eq("buy_order_id", buyOrderId);
		
		return ResultInfo.success(this.getOne(queryWrapper));
	}
    
	
	
	

	@Override
	public ResultInfo selectBuyOrder(Integer currentPage, Integer pageSize, String searchkey, String searchstart,
			String searchstart1, String searchend,String searchend1, String searchstatus) {
		QueryWrapper<BuyOrderClientShopVo> buyOrderWrapper = new  QueryWrapper<BuyOrderClientShopVo>();
		if (StringUtils.hasLength(searchkey)) {
			buyOrderWrapper.like("shop_name",searchkey).
					         or().like("buy_order_id", searchkey). 
					         or().like("client_name",searchkey);
		}
		if (StringUtils.hasLength(searchstatus)) {
			
			if ("已支付".equals(searchstatus)) {
				buyOrderWrapper.eq("order_status", true);
			}else if ("待支付".equals(searchstatus)) {
				buyOrderWrapper.eq("order_status", false);
			} 
		}
		if (StringUtils.hasLength(searchstart)) {
			buyOrderWrapper.between("exercise_start", searchstart, searchstart1);
		}
		if (StringUtils.hasLength(searchend)) {
			buyOrderWrapper.between("exercise_end", searchend, searchend1);
		}
		buyOrderWrapper.eq("delete_flag", true);
		IPage<BuyOrderClientShopVo> pageInfo = new Page<BuyOrderClientShopVo>(currentPage,pageSize);
		return ResultInfo.success(this.page(pageInfo,buyOrderWrapper));
	}



	@Override
	public ResultInfo selectOrders(Integer currentPage, Integer pageSize, Integer clientId) {
		QueryWrapper<BuyOrderClientShopVo> buyOrderWrapper = new  QueryWrapper<BuyOrderClientShopVo>();
		buyOrderWrapper.eq("client_id", clientId).eq("delete_flag", true);
		IPage<BuyOrderClientShopVo> pageInfo = new Page<BuyOrderClientShopVo>(currentPage,pageSize);
		return ResultInfo.success(this.page(pageInfo,buyOrderWrapper));
	}


	
	

		

}
